﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Imaging;

namespace AudioBooks.Data
{
    public class Chapter : AudioBooks.Common.BindableBase
    {
        private static Uri _baseUri = new Uri("ms-appx:///");

        public string intId { get; set; }
        public string chrChapterName { get; set; }
        public string intIdCat { get; set; }
        public string chrFileSize { get; set; }
        public string chrDuration { get; set; }
        public string chrChapterUrl { get; set; }
        public string intSortBy { get; set; }

        private ImageSource _image = null;
        public String _imagePath = null;
        public ImageSource Image
        {
            get
            {
                if (this._image == null && this._imagePath != null)
                {
                    this._image = new BitmapImage(new Uri(Chapter._baseUri, this._imagePath));
                }
                return this._image;
            }
            set
            {
                this._imagePath = null;
                this.SetProperty(ref this._image, value);
            }
        }
    }

    public class Book : AudioBooks.Common.BindableBase
    {
        private static Uri _baseUri = new Uri("ms-appx:///");

        public string title { get; set; }
        public string bookId { get; set; }
        public string shortDescrip { get; set; }
        public string longDescript { get; set; }
        public string price { get; set; }
        public string publish_date { get; set; }

        public string author { get; set; }

        private ImageSource _image = null;
        public String _imagePath = null;
        public ImageSource Image
        {
            get
            {
                if (this._image == null && this._imagePath != null)
                {
                    this._image = new BitmapImage(new Uri(Book._baseUri, this._imagePath));
                }
                return this._image;
            }
            set
            {
                this._imagePath = null;
                this.SetProperty(ref this._image, value);
            }
        }
    }

    public class NewChapter : AudioBooks.Common.BindableBase
    {
        public string id { get; set; }
        private string _name;
        public string name { 
                get 
                {
                    return _name;
                }
                set
                {
                    _name = value;
                    this.SetProperty(ref this._name, value);
                }
            }
        public string fileSize { get; set; }
        public string duration { get; set; }
        public string url { get; set; }
        public bool status { get; set; }
        public double _percent;

        
        public double percent
        {
            get
            {
                return _percent;
            }
            set
            {
                _percent = value;
                this.SetProperty(ref this._percent, value);
            }
        }
    }

    public class ListItemDataTemplateSelector : DataTemplateSelector
    {
        /// <summary>
        /// Chapter with downloading progress bar
        /// </summary>
        public DataTemplate ChapterWithProgress { get; set; }

        /// <summary>
        /// Downloaded Chapter
        /// </summary>
        public DataTemplate ChapterNormal { get; set; }

        protected override DataTemplate SelectTemplateCore(object item, DependencyObject container)
        {
            var newChapter = item as NewChapter;

            switch (newChapter.status)
            {
                case true:
                    return ChapterNormal;
                case false:
                    return ChapterWithProgress;
                default:
                    return ChapterNormal;
            }

            //return base.SelectTemplateCore(item, container);
        }
    }

    public class ShareContent
    {
        public string bookName { get; set; }
        public string message { get; set; }
    }
}
